package com.example.demo.controller;

import com.example.demo.service.LogService;
import com.example.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/trans2")
public class TransController2 {

    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;

    @Transactional //出现运行时发生异常或者error，自动执行事务回滚   没有发生异常或处理异常，正常提交
    @RequestMapping("/r1")
    public Boolean r1(String name, String password) {

        Integer result = userService.insertUser(name,password);
        log.info("数据影响行数： " + result);

        Integer logResult = logService.insertLog(name,"registry");
        log.info("数据影响行数： " + logResult);

        return true;
    }
}
